package com.untilov.gb.http.cookies;

import java.util.Vector;

public abstract class AbstractCookiesManager implements CookiesManagerIF {

    private Vector cookies;

    public Vector getCookies() {
        return cookies;
    }

    public boolean isCookiesValid() {
        int sid = 0;
        int cal = 0;
        int lsid = 0;
        int gausr = 0;

        // number of cookies has to at least 6 (CAL - caledar service? isn't
        // mandatory)
        if (this.cookies.size() < 6) {
            System.out.println("Number of cookies: " + this.cookies.size());
            return false;
        }
        for (int i = 0; i < cookies.size(); i++) {
            if (cookies.elementAt(i).toString().indexOf("LSID") != -1) {
                lsid++;
            } else if (cookies.elementAt(i).toString().indexOf("CAL") != -1) {
                cal++;
            } else if (cookies.elementAt(i).toString().indexOf("SID") != -1) {
                sid++;
            } else if (cookies.elementAt(i).toString().indexOf("GAUSR") != -1) {
                gausr++;
            }
        }
        // boolean result = sid == 1 && cal == 1 && lsid == 4 && gausr == 1;
        boolean result = sid == 1 && lsid == 4 && gausr == 1;
        if (!result) {
            System.out.println(sid + " " + cal + " " + lsid + " " + gausr);
        }
        return result;
    }

    public void setCookies(Vector cookies) {
        this.cookies = cookies;
    }
}
